﻿package mortal.game.view.copy.treasureHunt.renderer
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.utils.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.treasureHunt.*;
    import mortal.mvc.core.*;

    public class TreasureHuntBoxListCellRenderer extends GCellRenderer
    {
        private var _item:BaseItem;
        private var _boxInfo:TreasureHuntBoxInfo;

        public function TreasureHuntBoxListCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.setItemStyle(ItemStyleConst.Small);
            this._item.isShowLock = true;
            this._item.isDragAble = false;
            this.addChild(this._item);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.TreasureHuntUpdateBoxNum, this.onBoxNumUpdateHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.TreasureHuntUpdateBoxNum, this.onBoxNumUpdateHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._boxInfo = param1 as TreasureHuntBoxInfo;
            if (this._boxInfo)
            {
                this._item.itemData = this._boxInfo.itemData;
                this._item.enabled = false;
            }
            return;
        }// end function

        private function onBoxNumUpdateHandler(event:DataEvent) : void
        {
            var _loc_3:String = null;
            var _loc_2:* = event.data as Dictionary;
            for (_loc_3 in _loc_2)
            {
                
                if (int(_loc_3) == this._boxInfo.bossCode)
                {
                    this._item.amount = int(_loc_2[_loc_3]);
                    this._item.enabled = true;
                    break;
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._item.dispose();
            this._item = null;
            this._boxInfo = null;
            this.removeListeners();
            return;
        }// end function

    }
}
